package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.QuestionVOsBean;
import com.fancy.learncenter.bean.StudentWorkAnsDataBean;
import com.fancy.learncenter.ui.activity.CartoonPreviewWorkActivity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hyy on 2018/4/24.
 */

public class ActivityStudentWorkAdapter extends CommonRecycleViewAdapter<StudentWorkAnsDataBean.ResultBean> {

    public ActivityStudentWorkAdapter(Context mContext, List<StudentWorkAnsDataBean.ResultBean> itemDatas) {
        super(mContext, R.layout.cartoon_student_work_item, itemDatas);
    }

    @Override
    public void bindView(CustomViewHold customViewHold, StudentWorkAnsDataBean.ResultBean item, final int position) {

        TextView ans_state = customViewHold.getView(R.id.ans_state);
        TextView ans_tv = customViewHold.getView(R.id.ans_tv);

        if ("0".equals(item.getQuestionState())) {
            ans_state.setText("错误");
            ans_state.setTextColor(Color.parseColor("#FA1733"));
        } else {
            ans_state.setText("正确");
            ans_state.setTextColor(Color.parseColor("#00c9b9"));
        }

        SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);
        SimpleDraweeView simpleDraweeView2 = customViewHold.getView(R.id.simpleDraweeView2);
        SimpleDraweeView simpleDraweeView3 = customViewHold.getView(R.id.simpleDraweeView3);
        SimpleDraweeView simpleDraweeView4 = customViewHold.getView(R.id.simpleDraweeView4);

        if ("0".equals(item.getAnswerResources().get(0).getResourceType())) {
            simpleDraweeView.setVisibility(View.GONE);
            ans_tv.setText(item.getAnswerResources().get(0).getResourceValue());
        } else {

            if (item.getAnswerResources().size() > 1) {
                simpleDraweeView2.setVisibility(View.VISIBLE);
                simpleDraweeView3.setVisibility(View.VISIBLE);
                simpleDraweeView4.setVisibility(View.VISIBLE);

                simpleDraweeView2.setImageURI(item.getAnswerResources().get(1).getResourceValue());
                simpleDraweeView3.setImageURI(item.getAnswerResources().get(2).getResourceValue());
                simpleDraweeView4.setImageURI(item.getAnswerResources().get(3).getResourceValue());
            }
            simpleDraweeView.setVisibility(View.VISIBLE);
            simpleDraweeView.setImageURI(item.getAnswerResources().get(0).getResourceValue());

        }


        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, CartoonPreviewWorkActivity.class);

                intent.putParcelableArrayListExtra("questionVOs", questionVOs);

                intent.putExtra("position", position);

                mContext.startActivity(intent);
            }
        });
    }

    private ArrayList<QuestionVOsBean> questionVOs;

    public ArrayList<QuestionVOsBean> getQuestionVOs() {
        return questionVOs;
    }

    public void setQuestionVOs(ArrayList<QuestionVOsBean> questionVOs) {
        this.questionVOs = questionVOs;
    }
}
